<template>
  <div ref="echarts" style="width: 100%; height: 300px; margin: 0 auto"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  props: ["options"],
  mounted() {
    this.draw();
  },
  methods: {
    draw() {
      var myChart = echarts.init(this.$refs.echarts);
      // 指定图表的配置项和数据
      var option = {
        title: {
          //   text: "折线图堆叠",//标题动态数据
          text: this.options.text,
        },
        tooltip: {
          trigger: "axis",
        },
        dataset: {
          source:this.options.source
        },
        legend: {},
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          type: "category",
        },
        yAxis: {
          type: "value",
        },
        //核心数据 动态数据
        series: [{ type: "bar" }, { type: "bar" }, { type: "bar" }],
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);

      console.log("此时完成了报表渲染");
    },
  },
  watch: {
    option(newVal, oldVal) {
      console.log(newVal);
      console.log(oldVal);
      this.draw();
    },
  },
};
</script>

<style lang="scss" scoped>
</style>